package models;

import beans.PageBean;
import beans.RecommendBean;
import beans.WebServiceBean;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import java.util.List;

/**
 * 
 * @author Chen
 * 2014/9/20
 */
@Entity
@Table(name = "product_recommended")
public class Recommend extends BasicModel {
	//名称
	@Column(name = "name")
	public String name;

	//保存商品或者宣传文章的id
	@Column(name = "key_id")
	public String keyId;

	//推荐的图片id
	@Column(name = "photo_id")
	public String photo_id;

    @Column(name = "type")
    public int type;
	//权重
	@Column(name = "weight",columnDefinition ="int default 0")
	public int weight;

    @Column(name = "content", columnDefinition = "text")
    public String content;

	public static List<Recommend> getData(int size) {
		return find("type = ? order by weight asc,createTime desc",0).fetch(size);
	}

    public static List<Recommend> getData_activity(int size) {
        return find("type = ? order by weight asc,createTime desc",1).fetch(size);
    }
    /**
     * 前端ajax获取推荐的接口
     * @param size
     */
    public static List<RecommendBean> getRecommend(int size){
        List<Recommend> RecommendedList =  Recommend.getData(size);
        List<RecommendBean> list = RecommendBean.buildList(RecommendedList);
        return  list;
    }

    public static List<RecommendBean> getActivity(int size){
        List<Recommend> RecommendedList =  Recommend.getData_activity(size);
        List<RecommendBean> list = RecommendBean.buildList(RecommendedList);
        return  list;
    }
	
}
